package org.rslai.tcedit.business.impl;

import java.util.List;
import org.rslai.tcedit.business.TestCaseService;
import org.rslai.tcedit.domain.TestCase;
import org.rslai.tcedit.domain.TestCaseHistory;
import org.rslai.tcedit.util.StrUtil;

/**
 * TestCaseService 接口的实现<br/>
 * 注意: <tx:annotation-driven /> 这些方法已支持事务
 * 
 * @author rslai
 * 
 * @spring.bean id="testCaseService"
 */
public class TestCaseServiceImpl extends AbstractBaseService implements TestCaseService {

	public void create(String productID, Object object) {
		TestCase testCase = (TestCase)object;

		super.create(productID, testCase);

		TestCaseHistory testCaseHistory = new TestCaseHistory();
		testCaseHistory.setTestCaseID(testCase.getId());
		testCaseHistory.setVersion(testCase.getVersion());
		testCaseHistory.setCatalogID(testCase.getCatalogID());
		testCaseHistory.setDescribing(testCase.getDescribing());
		testCaseHistory.setPremiss(testCase.getPremiss());
		testCaseHistory.setCaseState(testCase.getCaseState());
		testCaseHistory.setRemark(testCase.getRemark());
		testCaseHistory.setStepsStr(testCase.getStepsStr());
		testCaseHistory.setExResultStr(testCase.getExResultStr());
		testCaseHistory.setUser(testCase.getUser());
		testCaseHistory.setEditDate(testCase.getEditDate());
		testCaseHistory.setSequence(testCase.getSequence());
		this.testCaseHistoryDao.create(productID, testCaseHistory);
	}

	public void update(Object object) {
		TestCase testCase = (TestCase)object;

		super.update(testCase);

		TestCaseHistory testCaseHistory = new TestCaseHistory();
		testCaseHistory.setTestCaseID(testCase.getId());
		testCaseHistory.setVersion(testCase.getVersion());
		testCaseHistory.setCatalogID(testCase.getCatalogID());
		testCaseHistory.setDescribing(testCase.getDescribing());
		testCaseHistory.setPremiss(testCase.getPremiss());
		testCaseHistory.setCaseState(testCase.getCaseState());
		testCaseHistory.setRemark(testCase.getRemark());
		testCaseHistory.setStepsStr(testCase.getStepsStr());
		testCaseHistory.setExResultStr(testCase.getExResultStr());
		testCaseHistory.setUser(testCase.getUser());
		testCaseHistory.setEditDate(testCase.getEditDate());
		testCaseHistory.setSequence(testCase.getSequence());
		this.testCaseHistoryDao.create(StrUtil.getProductID(testCase.getClass().getName()), testCaseHistory);
	}

	public List<TestCase> queryTestCase(String productID, String catalogID, boolean asc) {
		return testCaseDao.query(productID, catalogID, asc);
	}

	public Long countTestCase(String productID, String catalogID) {
		return testCaseDao.countTestCase(productID, catalogID);
	}

}
